import {Result} from '@/base/Result';
import {request} from '@/base/Request';
import {Page} from '@/base/Page';
import {MainTain} from '@/base/model/MainTain';
import qs from 'qs'
import {MainTainRecord} from '@/base/model/MainTainRecord';
import {Banners} from '@/base/model/Banners';
import {MaintenanceModel} from '@/base/model/MaintenanceModel';
import {LabelData} from '@/base/model/Label';

export function getMaintainList(params: {
  pageIndex: number,
  pageSize: number,
  type:number,
  deviceSn?:string,
  name?:string,
  tel?:string,
  sortDirection?: string,
  createBegin?: string,
  createEnd?: string,
  state?: string,
  searchAgentId?: number,
  cityId?: number,
  modelName?: string,
  provinceId?: number
}): Promise<Result<Page<MainTain>>> {
  return request.getPage(MainTain, '/api/post-sale/fetchMaintainList', {params});
}

export function getMaintainDetail(params: {
  id : number,
  aid : number,
}): Promise<Result<String>> {
  return request.get(String, '/api/post-sale/maintainDetail', {params});
}
export function getFault(params: {
  id : number,
}): Promise<Result<String>> {
  return request.get(String, '/api/post-sale/faultGetById', {params});
}

export function getWorkerList(params: {
  dealerId : number,
}): Promise<Result<String>> {
  return request.get(String, '/api/post-sale/workerList', {params});
}

export function getDealerList(params: {
  dealerId : number,
}): Promise<Result<String>> {
  return request.get(String, '/api/post-sale/dealerList', {params});
}
export function postWorker(params: {
  id: number,
  userId: number
}) {
  return request.post(String, '/api/post-sale/allocate', qs.stringify(params));
}

export function postDealer(params: {
  id: number,
  dealerId: number
}) {
  return request.post(String, '/api/post-sale/transform', qs.stringify(params));
}
export function postFault(params: {
  faultId: string,
  id: number,
  faultInput: string,
  sn: string,
  pm: string,
  allType: number
}) {
  return request.post(String, '/api/post-sale/faultSaveV2', qs.stringify(params));
}
export function delWorker(params:{dealerId: number, id: number }): Promise<Result<void>> {
  return request.delete('/api/post-sale/cancelAllocate', {params});
}
export function delPostsale(params:{dealerId: number, id: number, sym:number }): Promise<Result<void>> {
  return request.delete('/api/post-sale/delPostsale', {params});
}

export function getMaintainRecordList(params: {
  pageIndex: number,
  pageSize: number,
  deviceSn?:string,
  name?:string,
  dealerName?:string,
  maintenanceName?:string,
  sortDirection?: string,
  createBegin?: string,
  createEnd?: string,
}): Promise<Result<Page<MainTainRecord>>> {
  return request.getPage(MainTainRecord, '/api/post-sale/fetchMaintenanceRecord', {params});
}
export function getMaintainRecordDetail(params: {
  id : number,
}): Promise<Result<String>> {
  return request.get(String, '/api/post-sale/maintenanceDetail', {params});
}
export function createWorker(params:{
  dealerId:number,
  nickName:string,
  phone: string,
  ps: string
}) {
  return request.post(String, `api/post-sale/createWorker`, qs.stringify(params));
}
export function getFaultList(): Promise<Result<String>> {
  return request.get(String, '/api/post-sale/faultList')
}

export function postorderOnline(params: {
  sortId: number,
  modelId: string,
  quantity: string,
  dealerName: string,
  remarkOrderNumber: string,
  consigneeName: string,
  mobilePhone: string,
  consigneeAddress: string,
  remark?: string
}) {
  return request.post(String, `api/post-sale/orderOnline`, qs.stringify(params));
}
